A modern real estate platform built with Next.js, PocketBase, and deployed on Cloudflare Workers using OpenNext.
A modern real estate platform built with Next.js, PocketBase, and deployed on Cloudflare Workers using OpenNext.
cp .env-example .env
.env with your PocketBase configuration:# PocketBase Configuration
NEXT_PUBLIC_POCKETBASE_API_URL=http://127.0.0.1:8090
# Add other required environment variables
# Install dependencies
pnpm install
# Generate PocketBase types and collections (runs automatically before dev)
pnpm run pb-types # Generate TypeScript types from PocketBase
pnpm run pb-collections # Generate collection structure
# Start development server with Turbopack
pnpm dev
Open http://localhost:3000 to view the application.
pnpm dev # Start development server with Turbopack
pnpm build # Build for production
pnpm start # Start production server locally
pnpm lint # Run ESLint
pnpm run pb-types # Generate TypeScript types from PocketBase schema
pnpm run pb-collections # Generate collection structure documentation
pnpm run analyze # Analyze bundle size with webpack-bundle-analyzer
pnpm run lighthouse # Run Lighthouse performance audit
pnpm run perf:build # Build and analyze bundle in one command
This project is configured for deployment on Cloudflare Workers using OpenNext.
# Preview build locally in Workers runtime (recommended for testing)
pnpm run preview
# This command:
# 1. Builds the Next.js app
# 2. Transforms it for Cloudflare Workers
# 3. Starts a local preview server
# Deploy to Cloudflare Workers
pnpm run deploy
# This command:
# 1. Builds the Next.js app for production
# 2. Transforms it for Cloudflare Workers
# 3. Deploys directly to your Cloudflare account
# Upload new version without deploying (for staged deployments)
pnpm run upload
# This command:
# 1. Builds and transforms the app
# 2. Uploads a new version to Cloudflare
# 3. Does not make it live (manual activation required)
# Generate Cloudflare environment types
pnpm run cf-typegen
# Generates cloudflare-env.d.ts with proper types for Workers runtime
npm install -g wrangler
# or
pnpm add -g wrangler
wrangler login
wrangler.jsonc:{
"name": "your-app-name", // Change this to your preferred worker name
"compatibility_date": "2024-12-30"
}
pnpm run deploy
NEXT_PUBLIC_POCKETBASE_API_URL and other required variablesThe application now uses Cloudflare R2 for advanced caching with regional cache optimization:
Current Setup (Production-Ready)
R2 Bucket Configuration
The app is configured with R2 bucket earth-and-home-cache for incremental caching:
// wrangler.jsonc
{
"r2_buckets": [
{
"binding": "NEXT_INC_CACHE_R2_BUCKET",
"bucket_name": "earth-and-home-cache"
}
]
}
OpenNext Caching Configuration
// open-next.config.ts
export default defineCloudflareConfig({
incrementalCache: withRegionalCache(r2IncrementalCache, {
mode: "long-lived", // 30-min cache for ISR/SSG responses
shouldLazilyUpdateOnCacheHit: true, // Background R2 refresh
}),
enableCacheInterception: true, // Better cold start performance
});
Creating Your Own R2 Bucket
If deploying to your own Cloudflare account:
# Create R2 bucket for caching
npx wrangler r2 bucket create your-app-cache
# Update wrangler.jsonc with your bucket name
# Update bucket_name in the r2_buckets configuration
All OpenNext commands have been tested and are working:
# Build the Next.js app
pnpm run build
# Build OpenNext worker for Cloudflare
npx opennextjs-cloudflare build
# Preview locally with Wrangler (recommended for testing)
npx opennextjs-cloudflare preview
# Deploy to Cloudflare Workers
npx opennextjs-cloudflare deploy
# Combined build and preview (from package.json)
pnpm run preview
# Combined build and deploy (from package.json)
pnpm run deploy
Command Explanations:
pnpm run build: Builds the Next.js application with production optimizationsopennextjs-cloudflare build: Converts Next.js build to Cloudflare Worker formatopennextjs-cloudflare preview: Starts local Wrangler dev server for testingopennextjs-cloudflare deploy: Uploads worker to Cloudflare and deployspnpm run preview: Convenience script that builds and previews in one commandpnpm run deploy: Convenience script that builds and deploys in one commandpublic/_headers file configures aggressive caching for static assetspnpm run analyze# View worker logs in real-time
wrangler tail
# Test worker locally
wrangler dev
# View worker status
wrangler whoami
The app now uses R2 caching successfully. If you encounter caching issues:
Current Working Configuration:
earth-and-home-cache public/_headersError: No R2 binding "NEXT_INC_CACHE_R2_BUCKET" found!
Solution: This was resolved by properly configuring the R2 bucket and OpenNext config:
earth-and-home-cacheNote: If deploying to your own account, create your own R2 bucket:
npx wrangler r2 bucket create your-bucket-name
# Then update bucket_name in wrangler.jsonc
Regional Cache Benefits:
mode: "long-lived": ISR/SSG responses cached for up to 30 minutesshouldLazilyUpdateOnCacheHit: true: Background cache refresh from R2Static Asset Optimization:
/_next/static/* files: 1-year immutable cacheCache Interception:
Future Enhancements Available:
revalidateTagpnpm run pb-types if PocketBase types are outdatedexport const runtime = "edge" statements (not supported)wrangler whoamiwrangler.jsoncpnpm run preview to test locally before deployingpnpm run analyzehljs ├── public/_headers # Cloudflare static asset caching rules
├── wrangler.jsonc # Cloudflare Worker configuration
├── open-next.config.ts # OpenNext configuration
├── .dev.vars # Local development environment variables
└── cloudflare-env.d.ts # Generated Cloudflare runtime types